
use ESS2002_2018.dta, clear


**gen intervention variable

gen piigs=0
replace piigs=1 if cntry=="ES" //Spain
replace piigs=1 if cntry=="GR" //greece
replace piigs=1 if cntry=="IE" //ireland
replace piigs=1 if cntry=="IT" //italy
replace piigs=1 if cntry=="PT" //portugal
label var piigs "Member of the GIIPS States"
label define PIIGS 0 "Not a GIIPS State" 1 "Part of the GIIPS"
label value piigs PIIGS


gen monitoring=0
replace monitoring=1 if year>2010 & (cntry=="GR"|cntry=="PT"|cntry=="IE") //greece, portugal and ireland
replace monitoring=1 if year>2011 & (cntry=="ES"|cntry=="IT") //spain and italy
label var monitoring "Economic Intervention"
label define MONITORING 0 "No Intervention" 1 "Subject to EU Economic Intervention"
label value monitoring MONITORING


gen age_cat=.
replace age_cat=1 if agea>15 & agea<24
replace age_cat=2 if agea>25 & agea<34
replace age_cat=3 if agea>35 & agea<44
replace age_cat=4 if agea>45 & agea<54
replace age_cat=5 if agea>55 & agea<64
replace age_cat=6 if agea>64

**Employment dummy
recode mnactic (1 = 1 "Employed") (3 = 2 "Unemployed") (2 = 3 "Student")(4 5 6 7 8 9 = 4 "NILF") (.b .c .d = .) (77 88 99 = .), gen(empstat)
label var empstat "Employment Status Last Week"



replace polintr=. if polintr>=7

recode polintr(1=4 "Very interested")(2=3 "Quite Interested")(3=2 "Hardly Interested")(4=1 "Not at all interested"), into(politic_interest)


gen rural=.
replace rural=1 if domicil>=4
replace rural=0 if domicil<4

gen election=cntryID*year

gen incomenew=income1 if income2==.
replace incomenew=income2 if income2!=.
replace incomenew=. if incomenew>10



merge m:m cntryID essround using CPDS_turnout.dta



***Main Table 1***
logit voted i.monitoring  i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using table1.doc, dec(2) replace
logit voted i.monitoring c.deficit  i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using table1.doc, dec(2) append
logit voted i.monitoring c.unemp_change i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using table1.doc, dec(2) append

**Odds Ratios***
logit voted i.monitoring  i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using table1_OR.doc,replace dec(2) ctitle(Odds ration) eform 
logit voted i.monitoring c.deficit  i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using table1_OR.doc,append dec(2) ctitle(Odds ration) eform 
logit voted i.monitoring c.unemp_change i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using table1_OR.doc,append dec(2) ctitle(Odds ration) eform 



*** Interaction models and plots***

**Education
logit voted i.monitoring##c.eduyrs c.unemp_change i.gender i.age_cat i.partner incomenew i.empstat i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using condition1.doc, dec(2) replace
margins monitoring, at(eduyrs=(1(1)24)) post
marginsplot, l(90) xlabel(1(1)24) addplot(histogram eduyrs if e(sample) & eduyrs<=24, discrete percent width(1) yaxis(2) yscale(alt) fcolor(%20) lc(black%30) )

**Ideology
logit voted i.monitoring##c.lrscale c.unemp_change c.eduyrs i.gender i.age_cat i.partner incomenew i.empstat i.rural politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using condition1.doc, dec(2) append
margins monitoring, at(lrscale=(0(1)10)) post
marginsplot, l(90) xlabel(0(1)10) addplot(histogram lrscale if e(sample), discrete percent width(1) yaxis(2) yscale(alt) fcolor(%20) lc(black%30) )

**Political interest
logit voted i.monitoring##c.politic_interest c.unemp_change c.eduyrs i.gender i.age_cat i.partner incomenew i.empstat i.rural c.lrscale i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
outreg2 using condition1.doc, dec(2) append
margins monitoring, at(politic_interest=(1(1)4)) post
marginsplot, l(90) xlabel(0(1)4) addplot(histogram politic_interest if e(sample), discrete percent width(0.5) yaxis(2) yscale(alt) fcolor(%20) lc(black%30) )



***AME table
logit voted i.monitoring i.gender i.age_cat c.eduyrs incomenew i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
margins, dydx(*) post
estimates store m1
outreg2 [m1] using margins1.doc, dec(2) replace

logit voted i.monitoring c.deficit  i.gender i.age_cat c.eduyrs incomenew  i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
margins, dydx(*) post
estimates store m2
outreg2 [m2] using margins1.doc, dec(2) append

logit voted i.monitoring c.unemp_change i.gender i.age_cat c.eduyrs incomenew  i.empstat i.partner i.rural c.lrscale politic_interest i.cntryID i.year if EU15==1 [pw=weight], cluster (cntryID)
margins, dydx(*) post
estimates store m3
outreg2 [m3] using margins1.doc, dec(2) append

